<?php


namespace Drupal\shushengyuan\Schemas;


use Drupal\shusy_store_coupon\Entity\ShusyStoreCouponHold;

class CouponHoldItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_store_coupon_hold';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyStoreCouponHold) {
      $value = [
        'id' => (int) $this->entity->id,
        'title' => (string) $this->entity->title,
        'amount' => t('¥@amount', ['@amount' => $this->convertYuan($this->entity->amount)]),
        'desc' => (string) $this->entity->description,
        'condition' => (string) t('满 ￥@min 运费可用', ['@min' => $this->convertYuan($this->entity->condition_min)]),
        'validity' => (string) $this->getValidity($this->entity),
      ];
      $this->merge($value);
    }
  }

  protected function getValidity(ShusyStoreCouponHold $hold) {
    return t('@start 至 @end', [
      '@start' => $this->formatDate($hold->validity_start, 'Y-m-d'),
      '@end' => $this->formatDate($hold->validity_end, 'Y-m-d'),
    ]);
  }
}
